<?php
/**
 * Created by PhpStorm.
 * User: wangwenshan
 * Date: 2019/1/21
 * Time: 15:17
 */

namespace app\api\controller\v1;


use app\api\validate\IDCollection;
use app\api\validate\IDMustBePositiveInt;
use app\api\model\Theme as ThemeModel;
use app\lib\exception\ThemeMissException;

class Theme
{
    /*
     * @url /theme?ids=1,2,3
     * @return 一组theme模型
     * */
    public function getSimpleList($ids=''){
        (new IDCollection())->getCheck();
        $ids = explode(',',$ids);
        $result = ThemeModel::with('topicImg,headImg')->select($ids);
        if(!$result){
            throw new ThemeMissException();
        }
        return $result;
    }
    /*
     * @url /theme:id
     * */
    public function getComplexOne($id){
        (new IDMustBePositiveInt())->getCheck();
        $theme = ThemeModel::with('products,topicImg,headImg')->find($id);
        if(!$theme){
            throw new ThemeMissException();
        }
        return $theme;
    }
}